const app = getApp();
const util = require("../../utils/util.js");
const api = require("../../utils/api.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        mainColor: app.pageColor.mainColor,
        goodInfo:{},
        upUrl:[],
        itemList:["快递/物流一直未到","货物破损已拒签","七天无理由退货","卖家发错货","商品质量问题","与图片描述不符"],
        item:"",
        money:"25",
        des:""
    },

    /**
     * 图片上传
     */
    upLoad:function(){
        if (this.data.upUrl.length>=3){
            util.failToast("最多三张")
            return;
        }
        var that = this;
        util.chooseImage(function (res) {
            var tempFilePaths = res.tempFilePaths;
            for (var i = 0; i < tempFilePaths.length;i++){
                util.uploadFile(tempFilePaths[i],function(res){
                    var data = JSON.parse(res.data)
                    console.log(data.data.url)
                    that.data.upUrl.push(data.data.url)
                    that.setData({
                        upUrl: that.data.upUrl
                    })
                },{})
            }
        }, 3)

        
       
    },

    opTap:function(){
        var that = this;
        wx.showActionSheet({
            itemList: this.data.itemList,
            success: function (res) {
                that.setData({
                    item:that.data.itemList[res.tapIndex]
                })
               
            },
            fail: function (res) {
                console.log(res.errMsg)
            }
        })
    },
    /**
     * 提交
     */
    submit:function(e){
        let url = api.refund();
        if (this.data.item==""){
            util.failToast("请选择退款原因")
            return;
        }
        if (this.data.money == "") {
            util.failToast("输入退款金额")
            return;
        }
        util.http(true,"POST", url, { order_detail_id: this.data.goodInfo.id, refund_reason: this.data.item, refund_explain: "", refund_price: this.data.money, img: this.data.upUrl},function(res){
            console.log(res)
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var goodInfo = JSON.parse(options.goodInfo)
        this.setData({
            goodInfo: goodInfo
        })
    },
    
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
        util.setNavigationBarTitle("申请退款");
    },
})